<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<c:choose>
	<c:when test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">
		<c:set var="lastPageNumber" value="${actionBean.queryResult.totalPageCount}"/>
		<c:set var="currentPageNumber" value="${actionBean.queryResult.pageNumber}"/>
		<c:set var="prePageNumber" value="${actionBean.queryResult.pageNumber - 1}"/>
		<c:set var="nextPageNumber" value="${actionBean.queryResult.pageNumber + 1}"/>
		
		<div id="paginationBar">
			<input type="button" id="firstPageBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			<input type="button" id="prePageBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			第 <input type="text" id="currentPageText" value="${currentPageNumber }" size="3" maxlength="4"> / ${lastPageNumber} 頁
			<input type="button" id="nextPageBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
			<input type="button" id="lastPageBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
		</div>
		
		<table id="listTable">
		<thead>
			<tr>
				<th>序號</th>
				<th>項目名稱</th>
				<th>類別</th>
				<!--<th>停用</th>
				--><!--<th>繳費單原始檔路徑</th>
				<th>客製化檢核類別名稱</th>
			
				--><th>&nbsp;</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${actionBean.queryResult.paginatedList}" var="viewObj" varStatus="rowstat">
			<tr id="tr-${rowstat.index}">
				<td align="left">${actionBean.queryResult.firstIndexForCurrentPage + rowstat.index+1 }</td>
				<td align="left">
					<input type="hidden" id="editFormatDefinition.formatDefinitionPk-${rowstat.index}" name="editFormatDefinition.formatDefinitionPk" value="${viewObj.formatDefinitionPk}"/>
					 <c:out value="${viewObj.formatName}"/>
					<input type="hidden" id="editFormatDefinition.formatName-${rowstat.index}" name="editFormatDefinition.formatName" value="${viewObj.formatName}" maxlength="20" />
				</td>
				<td align="left">
					<input type="hidden" id="editFormatDefinition.formatType-${rowstat.index}" name="editFormatDefinition.formatType" value="${viewObj.formatType}"/>
					<c:choose>
						<c:when test="${1 == viewObj.formatType}">繳費單</c:when>
						<c:otherwise>繳款人</c:otherwise>
					</c:choose>
				</td>
				<!--<td align="left">
					<input type="checkbox" id="editFormatDefinition.deleted-${rowstat.index}" name="editFormatDefinition.deleted" value="true" <c:if test="${viewObj.deleted }">checked="checked"</c:if> class="chk" />
				</td>
				-->
				<!--<td align="left">
				     <c:out value="${viewObj.jrxmlPath}"/>
					<input type="hidden" size="15" id="editFormatDefinition.jrxmlPath-${rowstat.index}" name="editFormatDefinition.jrxmlPath" value="${viewObj.jrxmlPath}" maxlength="60" />
				</td>
				<td align="left">
				   <c:out value="${viewObj.customValidateClass}"/>
					<input type="hidden" size="15" id="editFormatDefinition.customValidateClass-${rowstat.index}" name="editFormatDefinition.customValidateClass" value="${viewObj.customValidateClass}" maxlength="60" />
				</td>
				--><!--<td align="center">
				
					<c:choose>
						<c:when test="${viewObj.batchUsed}"></c:when>
						<c:otherwise>
							<input type="button" id="saveBtn-${rowstat.index}" name="doSave" value="確認" />
							<input type="button" id="deleteBtn-${rowstat.index}" name="doDelete" value="刪除" />
						</c:otherwise>
					</c:choose>
					
					<input type="button" id="editComissionBtn-${rowstat.index}" name="toEditComission" value="手續費設定" />
				</td>-->
				<td>
					<div id="toAjaxEditImg-<c:out value='${viewObj.formatDefinitionPk}'/>"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
				    <input type="hidden" size="15" id="editFormatDefinition.group.groupNo" name="editFormatDefinition.group.groupNo" value="<c:out value='${viewObj.group.groupNo}'/>" maxlength="60" />
				</td>
				
			</tr>
			</c:forEach>	
		</tbody>
	</table>
	<div id="paginationBar">		
		<input type="button" id="printBtn2" value="列印" />
	</div>
			
			
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$("[id^='firstPageBtn']").click(function() {
				doQueryAction(1);
			});
			
			$("[id^='prePageBtn']").click(function() {
				doQueryAction(<c:out value='${prePageNumber}'/>);
			});
			
			$("[id^='nextPageBtn']").click(function() {
				doQueryAction(<c:out value='${nextPageNumber}'/>);
			});
			
			$("[id^='lastPageBtn']").click(function() {
				doQueryAction(<c:out value='${lastPageNumber}'/>);
			});
			
			$("[id^='currentPageText']").change(function() {
				var value = this.value;
				if (value != ''){
					value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
					var intRegex = /^\d+$/;
					if(!intRegex.test(value)) {
						alert('頁數必須是整數');
						return ;
					}
					
					value = parseInt(value, 10);
					
					if (value < 1){
						alert('頁數必須是大於1');
						return ;
					}
					else if (value > <c:out value='${lastPageNumber}'/>){
						alert('頁數必須是小於總頁數 (<c:out value='${lastPageNumber}'/>)');
						return ;
					}
					else if (value != <c:out value='${currentPageNumber}'/>){
						doQueryAction(value);
					}
					
				}
				else{
					alert('頁數不可為空白');
					return ;
				}
			});
			
			
			
			$("[id^='toAjaxEditImg-']").click(function() {
				var formatDefinitionPk = this.id.substring(14);
				doEditFomatDefinition(formatDefinitionPk);
				
			});
			
			
			function doEditFomatDefinition(formatDefinitionPk){
												
				waitingDialog({});
				$.ajax({
					url : "<c:url value='/ajax/Soez9008.action'/>",
					async : true,
					type : 'POST',
					data : {toAjaxEditFomatDefinition: 'toAjaxEditFomatDefinition', 'editFormatDefinition.formatDefinitionPk': formatDefinitionPk},
					dataType : 'html',
					success : function(data, textStatus, XMLHttpRequest) {						
						$("#editFormatDefinitionDiv").html('');					
						$("#editFormatDefinitionDiv").html(data);
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
						$("#ajaxErrorMessageDiv").dialog({
							title : '系統錯誤',
							width : 600,
							resizable : false,
							modal : true,
							buttons : {
								Ok : function() {
									$(this).dialog("close");
								}
							}
						});
					},
					complete : function(XMLHttpRequest, textStatus) {
						closeWaitingDialog();
					}
				});
			}
			
			
			
			
			
			$('#printBtn2').click(function() {
				divPrint('queryResultDiv');
			});
			
			
			
		});
		//-->
		</script>
	</c:when>
	<c:otherwise>
		<div id="queryNothingBlockDiv" style="display: none;">
			查無資料
		</div>		
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$( "#queryNothingBlockDiv" ).dialog({  title:'帳單項目設定' ,width: 300, resizable: false, modal: true, buttons : {
				Ok : function() {
					$(this).dialog("close");
				}
			}  });
		});
		//-->
		</script>
	</c:otherwise>
</c:choose>